package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.EmployeeDAO;
import cn.edu.scau.cmi.hombio.dao.TaskDAO;
import cn.edu.scau.cmi.hombio.dao.TaskEmployeeDAO;

import cn.edu.scau.cmi.hombio.domain.Employee;
import cn.edu.scau.cmi.hombio.domain.Task;
import cn.edu.scau.cmi.hombio.domain.TaskEmployee;

import cn.edu.scau.cmi.hombio.service.TaskEmployeeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for TaskEmployee entities
 * 
 */

@Controller("TaskEmployeeRestController")

public class TaskEmployeeRestController {

	/**
	 * DAO injected by Spring that manages Employee entities
	 * 
	 */
	@Autowired
	private EmployeeDAO employeeDAO;

	/**
	 * DAO injected by Spring that manages Task entities
	 * 
	 */
	@Autowired
	private TaskDAO taskDAO;

	/**
	 * DAO injected by Spring that manages TaskEmployee entities
	 * 
	 */
	@Autowired
	private TaskEmployeeDAO taskEmployeeDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for TaskEmployee entities
	 * 
	 */
	@Autowired
	private TaskEmployeeService taskEmployeeService;

	/**
	 * Delete an existing Task entity
	 * 
	 */
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/task/{task_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskEmployeeTask(@PathVariable Integer taskemployee_id, @PathVariable Integer related_task_id) {
		taskEmployeeService.deleteTaskEmployeeTask(taskemployee_id, related_task_id);
	}

	/**
	* View an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/employee/{employee_id}", method = RequestMethod.GET)
	@ResponseBody
	public Employee loadTaskEmployeeEmployee(@PathVariable Integer taskemployee_id, @PathVariable Integer related_employee_id) {
		Employee employee = employeeDAO.findEmployeeByPrimaryKey(related_employee_id, -1, -1);

		return employee;
	}

	/**
	* Create a new TaskEmployee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee", method = RequestMethod.POST)
	@ResponseBody
	public TaskEmployee newTaskEmployee(@RequestBody TaskEmployee taskemployee) {
		taskEmployeeService.saveTaskEmployee(taskemployee);
		return taskEmployeeDAO.findTaskEmployeeByPrimaryKey(taskemployee.getId());
	}

	/**
	* Select an existing TaskEmployee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}", method = RequestMethod.GET)
	@ResponseBody
	public TaskEmployee loadTaskEmployee(@PathVariable Integer taskemployee_id) {
		return taskEmployeeDAO.findTaskEmployeeByPrimaryKey(taskemployee_id);
	}

	/**
	* Create a new Task entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/task", method = RequestMethod.POST)
	@ResponseBody
	public Task newTaskEmployeeTask(@PathVariable Integer taskemployee_id, @RequestBody Task task) {
		taskEmployeeService.saveTaskEmployeeTask(taskemployee_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* View an existing Task entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/task/{task_id}", method = RequestMethod.GET)
	@ResponseBody
	public Task loadTaskEmployeeTask(@PathVariable Integer taskemployee_id, @PathVariable Integer related_task_id) {
		Task task = taskDAO.findTaskByPrimaryKey(related_task_id, -1, -1);

		return task;
	}

	/**
	* Show all TaskEmployee entities
	* 
	*/
	@RequestMapping(value = "/TaskEmployee", method = RequestMethod.GET)
	@ResponseBody
	public List<TaskEmployee> listTaskEmployees() {
		return new java.util.ArrayList<TaskEmployee>(taskEmployeeService.loadTaskEmployees());
	}

	/**
	* Get Task entity by TaskEmployee
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/task", method = RequestMethod.GET)
	@ResponseBody
	public Task getTaskEmployeeTask(@PathVariable Integer taskemployee_id) {
		return taskEmployeeDAO.findTaskEmployeeByPrimaryKey(taskemployee_id).getTask();
	}

	/**
	* Save an existing TaskEmployee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee", method = RequestMethod.PUT)
	@ResponseBody
	public TaskEmployee saveTaskEmployee(@RequestBody TaskEmployee taskemployee) {
		taskEmployeeService.saveTaskEmployee(taskemployee);
		return taskEmployeeDAO.findTaskEmployeeByPrimaryKey(taskemployee.getId());
	}

	/**
	* Save an existing Task entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/task", method = RequestMethod.PUT)
	@ResponseBody
	public Task saveTaskEmployeeTask(@PathVariable Integer taskemployee_id, @RequestBody Task task) {
		taskEmployeeService.saveTaskEmployeeTask(taskemployee_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Delete an existing TaskEmployee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskEmployee(@PathVariable Integer taskemployee_id) {
		TaskEmployee taskemployee = taskEmployeeDAO.findTaskEmployeeByPrimaryKey(taskemployee_id);
		taskEmployeeService.deleteTaskEmployee(taskemployee);
	}

	/**
	* Create a new Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/employee", method = RequestMethod.POST)
	@ResponseBody
	public Employee newTaskEmployeeEmployee(@PathVariable Integer taskemployee_id, @RequestBody Employee employee) {
		taskEmployeeService.saveTaskEmployeeEmployee(taskemployee_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Get Employee entity by TaskEmployee
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/employee", method = RequestMethod.GET)
	@ResponseBody
	public Employee getTaskEmployeeEmployee(@PathVariable Integer taskemployee_id) {
		return taskEmployeeDAO.findTaskEmployeeByPrimaryKey(taskemployee_id).getEmployee();
	}

	/**
	* Save an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/employee", method = RequestMethod.PUT)
	@ResponseBody
	public Employee saveTaskEmployeeEmployee(@PathVariable Integer taskemployee_id, @RequestBody Employee employee) {
		taskEmployeeService.saveTaskEmployeeEmployee(taskemployee_id, employee);
		return employeeDAO.findEmployeeByPrimaryKey(employee.getId());
	}

	/**
	* Delete an existing Employee entity
	* 
	*/
	@RequestMapping(value = "/TaskEmployee/{taskemployee_id}/employee/{employee_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskEmployeeEmployee(@PathVariable Integer taskemployee_id, @PathVariable Integer related_employee_id) {
		taskEmployeeService.deleteTaskEmployeeEmployee(taskemployee_id, related_employee_id);
	}
}